<?php
// +----------------------------------------------------------------------
// | YFCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: rainfer <81818832@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\admin\model\User as UserModel;
use app\admin\model\AuthRule;
use think\Db;
use think\Cache;

class Loginlog extends Base
{
    /**
     * 列表
     */
    public function LogList()
    {
        $user_data = session('userinfo');
        $where_cond = array(
            'uid' => $user_data['id']
        );
        $log_list=Db::name('login_log')->where($where_cond)->order('time','desc')->paginate(config('paginate.list_rows'),false,['query'=>get_query()]);
        $page = $log_list->render();
        $page=preg_replace("(<a[^>]*page[=|/](\d+).+?>(.+?)<\/a>)","<a href='javascript:ajax_page($1);'>$2</a>",$page);
        $this->assign('log_list',$log_list);
        $this->assign('page',$page);
        $this->assign('search_name','');

        if(request()->isAjax()){
            return $this->fetch('ajax_loglist');
        }else{
            return $this->fetch();
        }
    }

    /**
     * 添加
     */
    public function LogAdd()
    {
        $user_data = session('userinfo');
        $add_data = array(
            'uid' => $user_data['id'],
            'uname' => $user_data['user_name'],
            'ip' => trim($_SERVER['REMOTE_ADDR']),
            'time' => time()
        );
        $add_result = Db::name('login_log')->insert($add_data);
    }

}